package com.example.administrator.shzs.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.administrator.shzs.R;
import java.util.List;
import java.util.Map;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 首页 特色 Adapter
 * Created by Administrator on 2016/10/18.
 */

public class HomeRecycleViewAdapter extends RecyclerView.Adapter<HomeRecycleViewAdapter.ViewHollderr> {

    private List<Map<Object, Object>> datalist;
    private Context context;


    public interface IconRecycleOnclickListent {
        void onItemClick(View view, int postion);
    }

    private IconRecycleOnclickListent iconRecycleOnclickListent;

    public void setIconRecycleOnclickListent(IconRecycleOnclickListent iconRecycleOnclickListent ) {
        this.iconRecycleOnclickListent = iconRecycleOnclickListent;
    }


    public HomeRecycleViewAdapter(List<Map<Object, Object>> datalist, Context context) {
        this.datalist = datalist;
        this.context = context;
    }

    @Override
    public ViewHollderr onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_item, null);
        ViewHollderr viewHollderr = new ViewHollderr(view);
        return viewHollderr;
    }

    @Override
    public void onBindViewHolder(final ViewHollderr holder, final int position) {

        holder.imageView.setImageResource((Integer) datalist.get(position).get("image"));
        holder.textView.setText(datalist.get(position).get("name") + "");


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iconRecycleOnclickListent.onItemClick(holder.itemView,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }


    class ViewHollderr extends RecyclerView.ViewHolder {
        private TextView textView;
        private CircleImageView imageView;

        public ViewHollderr(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.Index_Text);
            imageView = (CircleImageView) itemView.findViewById(R.id.Index_CircleImageView);
        }
    }

}
